package com.tm.controller;

import com.tm.seurity.domain.User;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by lichuan on 2022-09-24.
 */
@RestController
public class TestController {


    @GetMapping("getTest")
    public Object getTest(String name){

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User principal = (User) authentication.getPrincipal();
        return principal;
    }

    @GetMapping("getTest2")
    @PreAuthorize("hasRole('teacher')")
    public Object getTest2(String name){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User principal = (User) authentication.getPrincipal();
        return principal;
    }
}
